package org.bhf.providers.security.authentication;

import com.google.inject.Inject;
import com.google.inject.Provider;

import javax.persistence.EntityManager;

import org.bhf.db.txn.Transaction;
import org.bhf.db.txn.TransactionPolicy;

class Logger
{
    @Inject
    private Provider<EntityManager> provider;

    /**
     * Log this event. So that failures, which often cause a rollback of the current transaction, may be logged,
     * logging is done in its own transaction.
     * @param authenticationLog Log record
     */
    @Transaction( unit = "authentication", policy = TransactionPolicy.REQUIRES_NEW )
    final void log( final AuthenticationLog authenticationLog )
    {
        provider.get().persist( authenticationLog );
    }
}